#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int MAXN=200007;
ll Triangle[MAXN];
ll res[MAXN];
ll a[MAXN];
ll n,m;
void YanHui() {
	memset(Triangle, 0, sizeof(Triangle));
	ll tmp;
	for (int i=0; i<n; ++i) {
		tmp=m-1+i;
		Triangle[i] = ((i&tmp)!=i? 0 : 1);
	}
}
int main() {
	int T;
	cin>>T;
	while (T--) {	
		cin>>n>>m;
		YanHui();
		for (int i=0; i<n; ++i) scanf("%lld", &a[i]);
		memset(res, 0, sizeof(res));
		for (int i=0; i<n; ++i) {
			if (Triangle[i]==1) {
				for (int j=i; j<n; ++j) {
					res[j]=res[j]^a[j-i];
				}
			}
		}
		for (int j=0; j<n; ++j) printf("%lld%c", res[j], (j==n-1? '\n': ' '));
	}
	return 0;
} 
